import {
  BaseScene
} from "../object/baseScene";

export class LoadScene extends BaseScene {
  constructor() {
    super({
      key: 'LoadScene'
    })
  }
  bg = null // 背景
  startBtn = null // 开始按钮

  initLoading() {
    this.loads = []
    let rad = 10
    let leftX = this.gameWidth / 2 - rad * 9
    for (let i = 0; i < 10; i++) {
      let c = this.add.circle(leftX, this.gameCenterY, rad, 0x5500ff)
      c.setScale(0.3, 0.3)
      this.tweens.add({
        targets: c,
        duration: 500,
        delay: i * 100,
        repeatDelay: 800,
        repeat: -1,
        yoyo: true,
        scale: 0.8
      })
      this.loads.push(c)
      leftX += rad * 2
    }
  }
  preload() {
    this.initLoading()
    // 静态图片组
    this.load.image('startBG', require('../../assets/imgs/startBG.png'))
    this.load.image('startBtn', require('../../assets/imgs/start_btn.png'))
    this.load.image('gameBG', require('../../assets/imgs/gameBG.png'))
    this.load.image('bomb', require('../../assets/imgs/bomb.png'))
    this.load.image('prop_bomb', require('../../assets/imgs/bomb_supply.png'))
    this.load.image('prop_buff', require('../../assets/imgs/bullet_supply.png'))
    // 音频组
    this.load.audio('bgm', require('../../assets/audio/bgm.mp3'))
    this.load.audio('gameover', require('../../assets/audio/gameover.mp3'))
    this.load.audio('getBuff', require('../../assets/audio/getBuff.mp3'))
    this.load.audio('do', require('../../assets/audio/ndo.mp3'))
    // 形体组
    this.load.json('shapes', require('../../assets/shape/shapes.json'))
    // 精灵组
    this.load.spritesheet('audio', require('../../assets/imgs/audio.png'), {
      frameWidth: 50,
      frameHeight: 41
    })
    this.load.spritesheet('player', require('../../assets/imgs/myPlane.png'), {
      frameWidth: 66,
      frameHeight: 82
    })
    this.load.spritesheet('smallPlane', require('../../assets/imgs/smallPlane.png'), {
      frameWidth: 34,
      frameHeight: 24
    })
    this.load.spritesheet('midPlane', require('../../assets/imgs/midPlane.png'), {
      frameWidth: 46,
      frameHeight: 64
    })
    this.load.spritesheet('bigPlane', require('../../assets/imgs/bigPlane.png'), {
      frameWidth: 110,
      frameHeight: 170
    })

  }
  create() {
    this.loads.forEach(child=>{
      child.destroy()
    })
    this.bg = this.add.image(this.gameCenterX, this.gameCenterY, 'startBG')
    this.startBtn = this.add.image(this.gameCenterX, this.gameCenterY + 100, 'startBtn')
    this.startBtn.setScale(0.5, 0.5)
    this.startBtn.setInteractive()
    this.startBtn.on('pointerdown', () => {
      this.scene.switch('GameScene')
    })


    // this.scene.switch('GameScene')

  }
  update() {

  }
}
